clear all;
clc;

load mnist_test;

X = xU';
[n,d] = size(X);

es = 0.4;
tic
IDX = [];
DIST = [];
ct = 1;
for i = 1:n
    dist = sqrt(sum((repmat(X(i,:),n,1) - X).^2,2));
    ix = find(dist < es);
    DIST = [DIST;dist(ix)];
end
toc